import 'package:flutter/material.dart';
import 'package:flutter_app/views/Repayment/index.dart';
import 'package:flutter_app/views/Credit/index.dart';
import 'package:flutter_app/views/Profile/index.dart';

// import 'package:app_flutter/pages/login.dart';
class BottomNav extends StatefulWidget {
  BottomNav({Key key, this.currentIndex}) : super(key: key);
  final int currentIndex;
  _BottomNavState createState() => _BottomNavState();
}

class _BottomNavState extends State<BottomNav> {
  int _currentIndex = 0;
  final List<Map<String, dynamic>> bottomNavList = [
    {"icon": Icons.home, "title": "Credit", "screen": Credit()},
    {"icon": Icons.payment, "title": "Repayment", "screen": Repayment()},
    {"icon": Icons.perm_identity, "title": "Me", "screen": ProfilePage()},
  ];

  Color _getActiveColor(int i) {
    return _currentIndex == i ? Colors.blue : Colors.black45;
  }

  List<BottomNavigationBarItem> _bottomNavWidget() {
    List<BottomNavigationBarItem> navList = [];
    for (var i = 0; i < bottomNavList.length; i++) {
      var item = bottomNavList[i];
      navList.add(BottomNavigationBarItem(
          icon: Icon(item['icon'], color: _getActiveColor(i)),
          title: Text(
            item['title'],
            style: TextStyle(color: _getActiveColor(i)),
          )));
    }
    return navList;
  }

  @override
  void initState() {
    super.initState();
    _currentIndex =
        widget.currentIndex == null ? _currentIndex : widget.currentIndex;
  }

  @override
  Widget build(BuildContext context) {
    print(_currentIndex);
    return Scaffold(
      // appBar: AppBar(
      //   title: Text(bottomNavList[_currentIndex]['title']),
      //   actions: <Widget>[
      //       IconButton( // action button
      //         icon: Icon(Icons.account_circle),
      //         onPressed: () {
      //           Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context){
      //             return LoginScreen();
      //           }));
      //         },
      //       ),
      //     ],
      // ),
      body: bottomNavList[_currentIndex]['screen'],
      bottomNavigationBar: BottomNavigationBar(
        items: _bottomNavWidget(),
        currentIndex: _currentIndex,
        onTap: (int index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}
